(function ($) {
    $.editCourse = function () {
        return {
            courseWareDTOList: {},
            init: function () {
                this.listener();
                this.courseList();
            }
            ,
            /**
             * 添加各按钮所需要的监听事件
             */
            listener: function () {
                //点击上传 触发事件
                $(".uploadcwp").on("click", function () {
                    $("#uploadcwp").click();
                });
                $("#uploadcwp").on("change", function () {
                    $(".cwpText").html("正在上传......");
                    if ($(this)[0].files.length) {
                        var list = document.getElementById("uploadcwp").files;
                        var listName = ($(this)[0].files)[0].name;
                        var inputName = listName.split(".");
                        var html = "";
                        uploadFile(SystemConfig.fileUploadUrl+ SystemConfig.appKey + "/", list[0], function (result) {
                            var result = JSON.parse(result);
                            if (result.status == 1000) {
                                //看上传的是ppt还是cwep
                                html = '<div class="item"><span class="cwpName" data-url=' + result.uploadFileDTO.fileId + '>' + listName + '</span></div>';
                                $(".cwpList").html(html);
                                $(".cwpText").html("");
                            }
                        });
                    }
                    //置空file
                    $(this).val("");
                });
                $("#editCourse").on("click", ".delCwp", function () {
                    $(this).parent().remove();
                });
            },
            courseList:function(){
                if(getParam("pptIndex")==""){
                    if(parent.length=="1"){
                        $.editCourse.courseWareDTOList=parent.$.courseList.courseWareGroupDTOList[getParam("index")].courseWareDTOList[0];
                    }else{
                        $.editCourse.courseWareDTOList=parent[0].$.courseList.courseWareGroupDTOList[getParam("index")].courseWareDTOList[0];
                    }
                }else{
                    if(parent.length=="1"){
                        $.editCourse.courseWareDTOList=parent.$.courseList.courseWareGroupDTOList[getParam("pptIndex")].courseWareDTOList[getParam("index")];
                    }else{
                        $.editCourse.courseWareDTOList=parent[0].$.courseList.courseWareGroupDTOList[getParam("pptIndex")].courseWareDTOList[getParam("index")];
                    }
                }
                //如果没有cwp
                if($.editCourse.courseWareDTOList.fileLength==0){
                    $(".cwp").css("display","none");
                }else{
                    var html='课件：<span>'+changeTime($.editCourse.courseWareDTOList.fileLength)+'</span><span class="delCwp" data-url='+$.editCourse.courseWareDTOList.fileUrl+'>[删除]</span>';
                    $(".cwp").html(html);
                }
                $(".remark input").val($.editCourse.courseWareDTOList.description);
                var html='<div class="item"><span class="cwpName" data-url=' + $.editCourse.courseWareDTOList.attachmentUrl+ '>'+ $.editCourse.courseWareDTOList.attachmentUrl+'</span></div>';
                $(".cwpList").html(html);
            }
        }
    }();
    $.editCourse.init();
})
(jQuery);